package com.yxx.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yxx.entityModel.vo.Result.ResponseResult;
import com.yxx.entityModel.vo.request.EmailRequest;
import com.yxx.entityModel.vo.response.UserInfoResponse;
import com.yxx.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 用户信息控制接口
 * @author yuxiangxun
 * @date 2025/1/26
 * @apiNote
 */

@Api(tags = "用户信息模块")
@RestController
public class UserInfoController {
    @Resource
    private UserService userService;

    /**
     * 获取登录用户信息
     * @return
     */
    @SaCheckLogin
    @ApiOperation(value = "获取登录用户信息")
    @GetMapping("/user/getUserInfo")
    public ResponseResult<UserInfoResponse> getUserInfo(){
        return ResponseResult.success(userService.getUserInfo());
    }

    /**
     * 修改用户密码
     * @param emailRequest
     * @return
     */
    @ApiOperation(value = "修改用户邮箱")
    @SaCheckPermission(value = "user:email:update")
    @PutMapping("/user/email")
    public ResponseResult<?> updateUserEmail(@Validated @RequestBody EmailRequest emailRequest){
        userService.updateUserEmail(emailRequest);
        return ResponseResult.success();
    }

    /**
     * 修改用户头像
     * @param file 文件
     * @return 头像地址
     */
    @ApiOperation(value = "修改用户头像")
    @SaCheckPermission(value = "user:avatar:update")
    @PostMapping("/user/avatar")
    public ResponseResult<String> updateUerAvatar(@RequestParam(value = "file")MultipartFile file){
        return ResponseResult.success(userService.updateUerAvatar(file));
    }
}
